home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-02-06 | 2.6 KB | 119 lines | [TEXT/CWIE] |
- /*
- ** Apple Macintosh Developer Technical Support
- **
- ** Functions to help you when you are building and sending Apple events.
- **
- ** by Pete Gontier, Apple Developer Technical Support
- **
- ** File: TrapUtils.c
- **
- ** Version: 1.0 PG Initial pass
- ** 1.1 AB Added prefix file for conditional macros
- ** Changed ? : notation to if else
- **
- ** Copyright © 1996 Apple Computer, Inc.
- ** All rights reserved.
- **
- ** You may incorporate this sample code into your applications without
- ** restriction, though the sample code has been provided "AS IS" and the
- ** responsibility for its operation is 100% yours. However, what you are
- ** not permitted to do is to redistribute the source as "DSC Sample Code"
- ** after having made changes. If you're going to re-distribute the source,
- ** we require that you make it clear in the source that the code was
- ** descended from Apple Sample Code, but that you've made changes.
- */
-
-
- // Private prefix file
- #include "Prefix.h"
-
- // System includes
- #include <OSUtils.h>
- #include <Traps.h>
-
- // Utility routines
- #include "TrapUtils.h"
-
-
- // ===============================================================================
-
- static pascal UInt16 CountToolboxTraps( void )
- {
- static UInt16 trapCount;
-
- if ( !trapCount )
- {
- if ( GetToolTrapAddress( _InitGraf ) == GetToolTrapAddress( 0xAA6E ) )
- {
- trapCount = 0x0200;
- }
- else
- {
- trapCount = 0x0400;
- }
- }
-
- return trapCount;
- }
-
- // ===============================================================================
-
- static pascal TrapType GetTrapType( UInt16 trapWord )
- {
- if ( trapWord & 0x0800 )
- {
- return ToolTrap;
- }
- else
- {
- return OSTrap;
- }
- }
-
- // ===============================================================================
-
- pascal Boolean TrapAvailable( UInt16 trapWord )
- {
- if ( GetTrapType( trapWord ) == OSTrap )
- {
- return GetToolTrapAddress( _Unimplemented ) != GetOSTrapAddress( trapWord );
- }
- else if ( ( trapWord & 0x07FF ) >= CountToolboxTraps () )
- {
- return false;
- }
- else
- {
- return GetToolTrapAddress( _Unimplemented ) != GetToolTrapAddress ( trapWord );
- }
- }
-
- // ===============================================================================
-
- pascal void * MyGetTrapAddress( UInt16 trapWord )
- {
- if ( GetTrapType( trapWord ) == OSTrap )
- {
- return GetOSTrapAddress( trapWord );
- }
- else
- {
- return GetToolTrapAddress( trapWord );
- }
- }
-
- // ===============================================================================
-
- pascal void MySetTrapAddress( UInt16 trapWord, void *newAddr )
- {
- if ( GetTrapType( trapWord ) == OSTrap )
- {
- SetOSTrapAddress( newAddr, trapWord );
- }
- else
- {
- SetToolTrapAddress( newAddr, trapWord );
- }
- }
-
-